<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加社团会员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="organ" class="layui-form-label">
                <span class="we-red">*</span>社团名
            </label>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <select id="organ" name="organ">
                        <option>请选择社团</option>
                    </select>
                </div>
            </div>
            <!--
            <div class="layui-input-inline">
                <select name="level">
                    <option>请选择分类</option>
                    <option value="1">五星社团</option>
                    <option value="2">四星社团</option>
                    <option value="3">三星社团</option>
                </select>
            </div>
            -->
        </div>
        <div class="layui-form-item">
            <label for="uid" class="layui-form-label">
                <span class="we-red">*</span>学号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="uid" name="uid" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="uname" class="layui-form-label">
                <span class="we-red">*</span>学生姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="uname" name="uname" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="we-red">*</span>手机号
           </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone" required="" lay-verify="phone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="qq" class="layui-form-label">
                <span class="we-red">*</span>QQ 号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="qq" name="qq" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label for="identity" class="layui-form-label">
                <span class="we-red">*</span>身份
            </label>
            <div class="layui-input-inline">
                <input type="text" id="identity" name="identity" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="uname" class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
        </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.extend({
        admin: '{/}../../static/js/admin'
    });
    layui.use(['form','layer','admin','jquery'], function(){
        var form = layui.form,
            admin = layui.admin,
            layer = layui.layer;
        var $ = layui.jquery;
        //form.render();
        //动态Select菜单

            $.ajax({
                type: "get",
                url: '/api/organ/queryOrganList',
                contentType:'application/json;charset=UTF-8',
                success: function(res) {
                    var data = res.data;
                    if(res.code == 0) {
                        $.each(data, function(index,item) {
                            $('#organ').append('<option value="'+item.id+'">'+item.name+'</option>');
                        });
                        form.render();
                    }
                }
            });

        //自定义验证规则
        form.verify({
          phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
            ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']

        });
        $.ajax({
            type:"post",
            url:'/api/admin/insertAccount',
            contentType:'application/json;charset=UTF-8',
            data:JSON.stringify(d),
            success: function(res) {
                if(res.code == 0) {
                    layer.alert("增加成功", {icon: 6}, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            var f = data.field;
            var organ = $('#organ').find( 'option:selected ').text();
            var d = {
                "oid":f.organ,
                "uid":f.uid,
                "organ":organ // "name": "value"
                ,"uname": f.uname
                ,"phone":f.phone
                ,"qq":f.qq
                ,"identity":f.identity,
            };
            $.ajax({
                type: "post",
                url: '/api/organ/user/insertOrganUser',
                contentType:'application/json;charset=UTF-8',
                data:JSON.stringify(d),
                success: function(res) {
                    if(res.code == 0) {
                        layer.alert("增加成功", {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else{
                        layer.alert("增加失败");
                    }
                }
            });
            return false;
        });
    });
</script>
</body>

</html>